/*--------------------------------------------渲染页面--------------*/
function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

var roomId = getQueryString("id");

$.ajax({
    type: "GET",
    url: "rest/room/find", //根据id查询记录
    data: {
        roomId: roomId
    },
    dataType: "json",
    success: function(data) {
        //获取到id=xxx的用户对象
        var room = data.data;
        $("#id").val(room.id);
        $("#name").val(room.name);
        $("#number").val(room.number);
        $("#teacher").val(room.teacher);
        //给提交按钮绑定事件
        $("#submitBtn").click(function() {
            updateRoom();
        })

    }
});
/*--------------------------------------------渲染页面--------------*/
function updateRoom() {
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "rest/room/update", //更新路径
        data: {
            roomId: $("#id").val(),
            roomName: $("#name").val(),
            roomNumber: $("#number").val(),
            roomTeacher: $("#teacher").val(),
        },
        success: function(data) {

            window.location.href = "rest/room/room"; //跳转到列表页面
        }

    });
}
